﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HPortal.Lib;
using System.Data;
using System.Data.SqlClient;
using System.Web.Security;

namespace HPortal.Module
{
    public partial class TimkiemDetai : PanelControl
    {   
        protected int ChannelID;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                cboLinhvuc.DataSource = DatabaseHelper.Select("Select LinhvucID,Ten From KH_Linhvuc");
                cboLinhvuc.DataTextField = "Ten";
                cboLinhvuc.DataValueField = "LinhvucID";
                cboLinhvuc.DataBind();
                cboLinhvuc.Items.Insert(0, new ListItem("Tất cả lĩnh vực", "0"));
                cboLinhvuc.SelectedIndex=0;


                cboLoai.DataSource = DatabaseHelper.Select("Select LoaiID,TenLoai From KH_Loai");
                cboLoai.DataTextField = "TenLoai";
                cboLoai.DataValueField = "LoaiID";
                cboLoai.DataBind();
                cboLoai.Items.Insert(0, new ListItem("Tất cả các loại","0"));
                cboLoai.SelectedIndex = 0;

                
                cboCap.DataSource = DatabaseHelper.Select("Select CapID,TenCap From KH_Cap");
                cboCap.DataTextField = "TenCap";
                cboCap.DataValueField = "CapID"; 
                cboCap.DataBind();
                cboCap.Items.Insert(0, new ListItem("Tất cả các cấp", "0"));
                cboCap.SelectedIndex = 0;

                cboNam.DataSource = DatabaseHelper.Select("Select Distinct Nam From KH_Tiendo ORDER BY Nam DESC");
                cboNam.DataTextField = "Nam";
                cboNam.DataValueField = "Nam";
                cboNam.DataBind();
                cboNam.Items.Insert(0, new ListItem("Tất cả các năm", "0"));
                cboNam.SelectedIndex = 0;
            }

        }
        private void grvManager_DataBind()
        {
            ChannelID =  DatabaseHelper.SelectScalarIntFromID("ChannelID", "Panel", PanelID);
            DataTable la = DatabaseHelper.Select("Exec [KH_TimkiemDetai] " + DatabaseHelper.EscapeQuote(txtKeyword.Text) + "," + cboLinhvuc.SelectedValue + "," + cboLoai.SelectedValue + "," + cboCap.SelectedValue + "," + cboNam.SelectedValue);
            this.grvLargeArticle.DataSource = la;
            grvLargeArticle.DataBind();
        }

        protected void cmdSearch_Click(object sender, EventArgs e)
        {
            grvManager_DataBind();
        }

        protected void grvLargeArticle_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            grvLargeArticle.PageIndex = e.NewPageIndex;
            grvManager_DataBind();
        }

    }
}